import javax.security.sasl.SaslServer;
import java.security.PublicKey;

/**
 * 实现一个简单的控制台版用户登陆程序, 程序启动提示用户输入用户名密码.
 * 如果用户名密码出错, 使用自定义异常的方式来处理
 */

class nameException extends Exception {
    public nameException(String name) {
        super(name);
    }
}

class passwordException extends Exception {
    public passwordException(String password) {
        super(password);
    }
}

public class Test {

    private String name = "张山";
    private String password="119229";

    public  void loginInfo(String name, String password) throws nameException,passwordException {
        if(!name.equals(this.name)) {
            throw new nameException("用户名错误");
        }
        if(!password.equals(this.password)) {
            throw new passwordException("密码错误");
        }
        System.out.println("登录成功");
    }

    public static void main(String[] args) {
        try {
            Test test = new Test();
            test.loginInfo("张山","123456");
        }
        catch (nameException e) {
            e.printStackTrace();
        }catch (passwordException e) {
            e.printStackTrace();
        }
    }

}

